package io.renren.modules.generator.controller;

import java.util.Arrays;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import io.renren.modules.generator.entity.ClassEntity;
import io.renren.modules.generator.service.ClassService;
import io.renren.common.utils.PageUtils;
import io.renren.common.utils.R;



/**
 *
 *
 * @author liangzai
 * @email liuyongxu@gmail.com
 * @date 2022-05-25 12:28:33
 */
@RestController
@RequestMapping("generator/class")
public class ClassController {
    @Autowired
    private ClassService classService;

    /**
     * 列表
     */
    @RequestMapping("/list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = classService.queryPage(params);

        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{classId}")
    public R info(@PathVariable("classId") Integer classId){
		ClassEntity classEntity = classService.getById(classId);

        return R.ok().put("class", classEntity);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    public R save(@RequestBody ClassEntity classEntity){
		classService.save(classEntity);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    public R update(@RequestBody ClassEntity classEntity){
		classService.updateById(classEntity);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    public R delete(@RequestBody Integer[] classIds){
		classService.removeByIds(Arrays.asList(classIds));

        return R.ok();
    }

    /**
     * 获取所有班级信息
     * @return
     */
    @RequestMapping("/selectAll")
    public R selectAll(){
        List<ClassEntity> classEntities = classService.selectAll();

        return R.ok().put("class", classEntities);
    }
}
